<?php

require_once ROOT_PATH . '/lib/models/surveys/Questions.php';
require_once ROOT_PATH . '/lib/models/surveys/Answers.php';
require_once ROOT_PATH . '/FirePHPCore/FirePHP.class.php';

class EXTRACTOR_Answers {

	public function parseAddData($postArr) {
		
		// Extract dates
		//$array=new array();		
		//die();
		$surveyId = $postArr['SurveyID'];
		$questions = Questions::getQuestionsBySurvey($surveyId);
		
		$answerArr = null;
		$i=0;
		foreach ($questions as $question){
			$answertype = $question->getAnswerType();
			$answerId = $question->getId();
			if($answertype==1){
				if(isset($postArr[$answerId])){
					$answer = new Answers();
					$answer->setQuestionId($answerId);
					$answer->setUser($_SESSION['empID']);
					$answer->setValue($postArr[$answerId]);
					$answer->setSurveyId($surveyId);
					$answerArr[$i]=$answer;
					$i++;
				}
			}else if($answertype==4){
				if(isset($postArr[$answerId])&& $postArr[$answerId]!= ''){
					$answer = new Answers();
					$answer->setQuestionId($answerId);
					$answer->setUser($_SESSION['empID']);
					$answer->setValue($postArr[$answerId]);
					$answer->setSurveyId($surveyId);
					$answerArr[$i]=$answer;
					$i++;
				}
			}else if($answertype==2){
				
				if(isset($postArr[$answerId])){					
					$answer = new Answers();
					$answer->setQuestionId($answerId);
					$answer->setUser($_SESSION['empID']);
					$answer->setValue($postArr[$answerId]);
					$answer->setSurveyId($surveyId);
					$answerArr[$i]=$answer;
					$i++;
				}
			}else if($answertype==3){
				//$firephp = FirePHP::getInstance(true);								
				if(isset($postArr[$answerId])&& count($postArr[$answerId])>0){
					for($j=0;$j<count($postArr[$answerId]);$j++){
						$answer = new Answers();
						$answer->setQuestionId($answerId);
						$answer->setUser($_SESSION['empID']);
						$answer->setValue($postArr[$answerId][$j]);
						$answer->setSurveyId($surveyId);
						$answerArr[$i]=$answer;
						$i++;
					}
					
				}
			}
		}
		
		return $answerArr;
	}
}
?>